import request from "@/utils/request";
// 查询所有的model的集合
export function getModel(params) {
  let name, types, url;
  if (params && Object.keys(params).length > 0) {
    name = params.name;
    types = params.preferTypes;
  }
  if (name) {
    if (types && types.length > 0) {
      url = `/virlib-admin/models?name=${name}`;
      types.map((item) => {
        url += `&&types=${item}`;
      });
    } else {
      url = `/virlib-admin/models?name=${name}`;
    }
  } else {
    if (types && types.length > 0) {
      url = `/virlib-admin/models?`;
      types.map((item) => {
        url += `types=${item}&&`;
      });
      url = url.slice(0, -2);
    } else {
      url = `/virlib-admin/models`;
    }
  }
  return request({
    url: url,
    method: "get",
    // data: params
  });
}

// 获取model 的分页列表
export function modelList(data) {
  return request({
    url: "/virlib-admin/model/query",
    method: "post",
    data: data,
  });
}

export function positionMsg(data) {
  return request({
    url: "/virlib-admin/position/query",
    method: "post",
    data,
  });
}

export function positionArr(type, name) {
  let url = `/virlib-admin/position/list`;
  if (name) {
    url = url + `?type=${type}&&name=${name}`;
  } else {
    url = url + `?type=${type}`;
  }
  return request({
    url: url,
    method: "get",
  });
}

// 新建
export function addModel(data) {
  return request({
    url: "/virlib-admin/model",
    method: "put",
    data,
  });
}

// 修改
export function editModel(data) {
  return request({
    url: "/virlib-admin/model",
    method: "post",
    data,
  });
}

// 删除
export function deleteModel(modelId) {
  return request({
    url: `/virlib-admin/model/${modelId}`,
    method: "delete",
  });
}
